<template>
  <div>
    <h1>标题: {{ title }}</h1>
    <button @click="title += '!'">修改标题</button>
    <hr>
    <h4>{{ person }}</h4>
    <h2>姓名: {{ name }}</h2>
    <h2>年龄: {{ age }}</h2>
    <h2>薪资: {{ job.j1.salary }}K</h2>
    <hr>
    <h3>{{  person }}</h3>
    <button @click="name += '!'">修改姓名</button>
    <button @click="age++">修改年龄</button>
    <button @click="job.j1.salary++">涨薪</button>
  </div>
</template>

<script>
import { ref, reactive, toRefs, readonly, shallowReadonly } from "vue";
export default {
  name: "Demo",
  setup() {

   /** 
    readonly: 让一个响应式数据变为只读的（深只读）。
    shallowReadonly：让第一层的响应式数据变为只读的（浅只读）
    应用场景：不希望数据被修改
  */


    let title = ref('你是风儿!')
  
    let person = reactive({
      name: "张三",
      age: 25,
      job: {
        j1: {
          salary: 6,
        },
      },
    });

    title = readonly(title)
    // person = readonly(person)
    person = shallowReadonly(person)

    return {
      title,
      person,
      ...toRefs(person),
    };
  },
};
</script>